﻿using System;

namespace Community.CsharpSqlite.Entity
{
    /*
    ** As each page of the file is loaded into memory, an instance of the following
    ** structure is appended and initialized to zero.  This structure stores
    ** information about the page that is decoded from the raw file page.
    **
    ** The pParent field points back to the parent page.  This allows us to
    ** walk up the BTree from any leaf to the root.  Care must be taken to
    ** unref() the parent page pointer when this page is no longer referenced.
    ** The pageDestructor() routine handles that chore.
    **
    ** Access to all fields of this structure is controlled by the mutex
    ** stored in MemPage.pBt.mutex.
    */

    public struct _OvflCell
    {
        /* Cells that will not fit on aData[] */
        public ushort idx; /* Insert this cell before idx-th non-overflow cell */
        public byte[] pCell; /* Pointers to the body of the overflow cell */

        public _OvflCell Copy()
        {
            var cp = new _OvflCell();
            if (pCell != null)
            {
                cp.pCell = Malloc.sqlite3Malloc(pCell.Length);
                Buffer.BlockCopy(pCell, 0, cp.pCell, 0, pCell.Length);
            }
            cp.idx = idx;
            return cp;
        }
    };
}